import inspect
from config.config_util import config
from domain import User
import dao as dao

__author__ = 'thanatos'


def test(loop):
    print('---------------')
    yield from dao.create_pool(loop, user='root', password='13824843156', db='WebBlog')
    user = User(name='victoria', password='123', email='victoria@gmail.com')
    yield from user.save()

# loop = asyncio.get_event_loop()
# loop.run_until_complete(test(loop))

print('globals function -->', globals())
print('locals function -->', locals())


def test_import():
    # mod = getattr(__import__('victoria.orm', globals(), locals(), ['orm']), 'orm')
    mod = __import__('victoria.orm', globals(), locals(), ['orm'])
    m = getattr(__import__('orm', globals(), locals()), 'Model')
    modd = __import__('orm', globals(), locals())
    pass


# test_import()
def test_select(loop):
    yield from dao.create_pool(loop=loop, host=config.db.host, port=config.db.port,
                               user=config.db.user, password=config.db.password,
                               db=config.db.database)
    # yield from User.findAll(None)
    # u = User(name='Thanatos', email='thanatos@gmail.com', password='123456', isAdmin=True)
    # yield from u.save()
    user = yield from User.findAll()
    print(user[0].isAdmin)
    if user[1].isAdmin:
        print('yes')
    else:
        print('no')
    print(user)


# loop = asyncio.get_event_loop()
# loop.run_until_complete(test_select(loop))

def func(*, a, b=2, c=None, **kwargs):
    pass


params = inspect.signature(func).parameters
for name, param in params.items():
    print('name is %s and param is %s' % (name, param))
    if param.kind == inspect.Parameter.POSITIONAL_ONLY:
        print('positional_only param : %s' % name)
    if param.kind == inspect.Parameter.POSITIONAL_OR_KEYWORD:
        print('positional_or_keyword param : %s' % name)
    if param.kind == inspect.Parameter.VAR_POSITIONAL:
        print('var_positional param : %s' % name)
    if param.kind == inspect.Parameter.KEYWORD_ONLY:
        print('keyword_only param : %s' % name)
    if param.kind == inspect.Parameter.VAR_KEYWORD:
        print('var_keyword param : %s' % name)

mod = __import__('base', globals(), locals())
Dict = getattr(mod, 'Dict')
print()

class V:

    def __init__(self):
        print('self module', self.__module__)
        print('the class is = ', self.__class__.__name__)


class P:
    v = V()

